home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / e_to_l / fbuilder / delphi / fbcomp.int < prev    next >
Text File  |  1996-09-15  |  7KB  |  193 lines

  1. {*
  2.  * FormulaBuilder 1.0
  3.  * YGB Software, Inc.
  4.  * Delphi Wrapper Class
  5.  * Copyright (c) 1995 Clayton Collie
  6.  * All Rights Reserved
  7.  *}
  8. {$F+,V-,X+,W-,G+,N+,A+}
  9. UNIT FBCOMP;
  10. INTERFACE
  11. uses classes,sysutils,fbcalc;
  12. CONST
  13.    MAXEXPRESSIONLEN = 1024;
  14.    MAXVARNAMELEN    = 30;
  15.  
  16.    EXPR_UNHANDLED_EVENT = 200;
  17.  
  18.  
  19. Type
  20.   TVarname  = String[MAXVARNAMELEN+1];
  21.  
  22.  
  23.   TVariable = Record
  24.      Name  : TVarName;
  25.      Value : TValueRec;
  26.   end;
  27.  
  28.  
  29.  
  30.   EFBError = Class(Exception)
  31.   Protected
  32.     fErrCode : Integer;
  33.   Public
  34.     Constructor CreateEcode(const ecode : integer);
  35.     Property ErrorCode : integer read fErrCode write fErrCode;
  36.   end;
  37.  
  38.  
  39.  
  40.   TFindVariableEvent = Procedure(const varname  : string;
  41.                                  var   vtype    : byte;
  42.                                  var   errcode  : integer;
  43.                                  var   vardata  : longint) of object;
  44.  
  45.   TGetVariableEvent  = Procedure(const varname  : string;
  46.                                  var   value    : TValueRec;
  47.                                  var   errcode  : integer;
  48.                                        vardata  : longint) of object;
  49.  
  50.   TSetVariableEvent  = Procedure(const varname  : string;
  51.                                  const value    : TValueRec;
  52.                                  var   errcode  : integer;
  53.                                        vardata  : longint) of object;
  54.  
  55.  
  56.  
  57.   TCustomExpression = class(TComponent)
  58.   private
  59.      {* unlisted *}
  60.   protected
  61.      fLines    : TStrings;
  62.      Procedure   SetExpression(const expr : pchar);  virtual;
  63.      Procedure   SetVariableCallbacks(CBKVFind   : TCBKFindVariable;
  64.                                       CBKVGetval : TCBKGetVariable;
  65.                                       CBKVSetVal : TCBKSetVariable;
  66.                                       lCBKData   : longint);
  67.     Procedure   FreeConstants;
  68.  
  69.     Property    UseEvents      : boolean
  70.                                  read fUseEvents write setUseEvents;
  71.  
  72.      Property   OnFindVariable : TFindVariableEvent
  73.                                  read  fOnFindVariable
  74.                                  write SetFindVarEvent;
  75.  
  76.      Property   OnGetVariable  : TGetVariableEvent
  77.                                  read  fOnGetVariable
  78.                                  write SetGetVarEvent;
  79.  
  80.      Property   OnSetVariable  : TSetVariableEvent
  81.                                  read  fOnSetVariable
  82.                                  write SetSetVarEvent;
  83.  
  84.  
  85.      Property    BooleanResult    : boolean   read  EvalAsBoolean;
  86.      Property    DateResult       : TDateTime read  EvalAsDate;
  87.      Property    FloatResult      : Double    read  EvalAsFloat;
  88.      Property    FunctionCount    : word      read  getFunctionCount;
  89.      Property    StringResult     : String    read  EvalAsString;
  90.      Property    IntResult        : Longint   read  EvalAsInt;
  91.  
  92.   Public
  93.      Constructor Create(aOwner : TComponent);  override;
  94.      Destructor  Destroy; override;
  95.      Procedure   Clear;    virtual;
  96.      Procedure   Reparse;  virtual;
  97.  
  98.      Procedure   EvaluatePrim(var value : TVALUEREC); virtual;
  99.      Procedure   AddVariable(const vname : TVarName;vtype : byte);
  100.      Procedure   getVarPtr(const vname : TVarName;var vtype : byte;var value : pointer);
  101.      Procedure   FreeVariable(const vname : TVarName);
  102.      Procedure   FreeVariableList;
  103.  
  104.      Procedure   AddConstantPrim(const cname : TVarName;value : TValueRec);
  105.      Procedure   AddStringConstant(const cname : TVarName;value : string);
  106.      Procedure   AddDateConstant(const cname : TVarName;value : TFBDate);
  107.      Procedure   AddNumericConstant(const cname : TVarName;value : double);
  108.      Procedure   AddBooleanConstant(const cname : TVarName;value : boolean);
  109.      Procedure   ParseAddVariable(const vname : TVarName;expr : string);
  110.      Procedure   ParseAddConstant(const cname : TVarName;expr : string);
  111.      Procedure   FreeConstant(const cname : TVarName);
  112.      {  }
  113.      Function    StatusText       : string;   virtual;
  114.  
  115.      Property    Formula          : String    read  getInfix
  116.                                               write setInfix;
  117.  
  118.      Property    AsString         : string    read  ValueAsString;
  119.                                             { write setInfix; }
  120.  
  121.      Property    Lines            : TStrings  read  FLines
  122.                                               write SetLines;
  123.  
  124.      Property    ReturnType       : byte      read  fReturnType;
  125.  
  126.  
  127.      Property    Status           : integer   read  fStatus
  128.                                               write setStatus;
  129.  
  130.      Property    StrFormula       : PChar     read  getExpression
  131.                                               write setExpression;
  132.  
  133.      Property    UseExceptions    : boolean   read  fUseExceptions
  134.                                               write fUseExceptions
  135.                                               default true;
  136.  
  137.      Property    VariableCount    : integer   read  getVariableCount;
  138.  
  139.      Property    VariableList[i : integer]:TVariable
  140.                                            read  getNthVarPrim
  141.                                            write setNthVarPrim;
  142.  
  143.      Property    Variables[const vname : TVarName] : TValueRec
  144.                                                read  getVariablePrim
  145.                                                write setVariablePrim;
  146.  
  147.      Property    StringValues[const vname : TVarName] : String
  148.                                                         read  getVarAsString
  149.                                                         write setVarFromString;
  150.  
  151.      Property    Constants[const cname : TVarName] : TValueRec
  152.                                               read  getConstantPrim
  153.                                               write AddConstantPrim;
  154.  
  155.      Property    Handle        : HEXPR   read fHandle;
  156.      Property    IsNULL        : boolean read fIsEmpty;
  157.  
  158.    { Events }
  159.  
  160.   end;
  161.  
  162.  
  163.   TExpression = Class(TCustomExpression)
  164.   Public
  165.      Property    AsBoolean;
  166.      Property    AsDate;
  167.      Property    AsFloat;
  168.      Property    AsInteger;
  169.      Property    AsString;
  170.      Property    FunctionCount;
  171.      Property    ReturnType;
  172.   Published
  173.      Property   Formula;
  174.      Property   Lines;
  175.      Property   UseExceptions;
  176.   { events }   
  177.      Property   OnFindVariable;
  178.      Property   OnGetVariable;
  179.      Property   OnSetVariable;
  180.      Property   UseEvents;
  181.   end;
  182.  
  183.  
  184.  Procedure Register;
  185.  
  186.  function ValueAsString(const Fvalue : TValueRec): string;
  187.  
  188.  Function getFunctionPrototypes(useResultType : boolean) : TStringList;
  189.  
  190.  
  191. IMPLEMENTATION
  192. END.
  193.